'''
商户管理： 新增商户
'''
from Lib.base.keywords import KeyWords
from selenium.webdriver.common.by import By
from Lib.common.common_function import *
from Lib.base.page_object.login_page import LonginPage


class BusinessAdd(KeyWords):
    # 新增商户页面
    url = KeyWords.url + 'business/business-editor?type=create'
    # 新增商户商户相关字段
    business_name = (By.XPATH, '//label[text()="商户名称"]/..//input')
    # 经营业态
    business_type = (By.XPATH, '//label[text()="经营业态"]/..//input')
    business_type_value = (By.XPATH, '//span[text()="餐饮"]')
    # 商户地址选择
    business_address_input = (By.XPATH, '//input[@placeholder="请选择商户地址"]')
    business_address_search_input = (By.XPATH, '//input[@placeholder="请输入地址关键字"]')
    business_address_search_button = (By.XPATH, '//i[contains(@class, "rz-icon-search")]')
    business_address_value = (By.XPATH, '//div[@class="address-picker--list"]/div[1]/h3/i')
    business_address_sure = (By.XPATH, '//span[text()="确定"]')
    # 商户照片
    business_photo_button = (By.XPATH, '//span[text()="上传图片"]')
    # 商户负责人和电话信息
    business_people = (By.XPATH, '//label[text()="商户负责人"]/..//input')
    business_phone = (By.XPATH, '//label[text()="联系手机"]/..//input')
    # 创建按钮
    create_button = (By.XPATH, '//span[text()="创建"]')
    # 断言元素
    add_assert = (By.XPATH, '//p[text()="新建商户成功"]')

    # 新建商户
    def business_add(self):
        self.open(self.url)
        self.wait(2)
        # 填写相关字段值
        self.input_value(args=self.business_name, text="UI自动化商户", context="商户名称")
        # 经营业态
        self.click(args=self.business_type, context="经营业态")
        self.wait(1)
        self.click(args=self.business_type_value, context="餐饮")
        self.wait(1)
        # 添加商户地址
        self.click(args=self.business_address_input, context="商户地址选择框")
        self.wait(2)
        self.input_value(args=self.business_address_search_input, text='上海市浦东新区', context="商户地址搜索框")
        self.wait(1)
        self.click(args=self.business_address_search_button, context="搜索按钮")
        self.wait(4)
        self.click(args=self.business_address_value, context="商户地址值")
        self.wait(1)
        self.click(args=self.business_address_sure, context="确定")
        self.wait(1)
        # 上传图片
        self.upload_by_exe(args=self.business_photo_button, context="商户图片")
        self.wait(2)
        # 添加商户负责人
        self.input_value(args=self.business_people, text="詹培", context="商户负责人")
        self.input_value(args=self.business_phone, text="18328816524", context="商户电话")
        self.wait(1)
        # 点击创建
        self.click(args=self.create_button, context="创建")
        return self.add_assert


if __name__ == '__main__':
    driver = choose_browser()
    L = LonginPage(driver)
    L.login('kobeAdmin002', 'kobe8888')
    case = BusinessAdd(driver)
    case.business_add()
